﻿using System;
using RockHopper.Common.Model;

namespace RockHopper.TrainingCalculator.WinRT.Utils
{
    public static class DoubleExtensions
    {
        public static string FormatPace(this double value, PaceUnitType units = PaceUnitType.Kilometres)
        {
            var minutes = TimeSpan.FromMinutes(value.ToMinutesPer(units));
            return minutes > TimeSpan.FromSeconds(90) 
                ? minutes.ToString(@"mm\:ss") 
                : minutes.TotalSeconds.Round(0).ToString();
        }

        public static string FormatTime(this double value)
        {
            var minutes = TimeSpan.FromMinutes(value);
            return minutes.ToString(@"hh\:mm\:ss");
        }

        public static string RoundToString(this double value, int dp = 1)
        {
            return Math.Round(value, dp, MidpointRounding.AwayFromZero).ToString();
        }

        public static double Round(this double value, int dp = 1)
        {
            return Math.Round(value, dp, MidpointRounding.AwayFromZero);
        }
    }
}
